package net.ithe.mapper;

import net.ithe.pojo.Clazz;
import net.ithe.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Mapper
public interface ClazzMapper {
    /**
     * 查分页询
     * @param clazzQueryParam
     * @return
     */
    public List<Clazz> list(ClazzQueryParam clazzQueryParam);
    /**
     * 根据id删除
     * @param id
     */
    void deleteByids(Integer id);
    /**
     * 保存员工
     * @param clazz
     */
    @Insert("INSERT INTO clazz(name,room,begin_date,end_date,master_id,subject,create_time,update_time)" +
            "values (#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void insert(Clazz clazz);
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("SELECT id,name,room,begin_date,end_date,master_id,subject,create_time,update_time FROM clazz WHERE id=#{id}")
    Clazz getById(Integer id);
    /**
     * 更新
     * @param clazz
     */
    @Update("UPDATE clazz SET name=#{name},room=#{room},begin_date=#{beginDate},end_date=#{endDate},master_id=#{masterId},subject=#{subject},update_time=#{updateTime} WHERE id=#{id}")
    void updateByClazz(Clazz clazz);
    /**
     * 获取所有班级信息
     * @return
     */
    @Select("SELECT id,name,room,begin_date,end_date,master_id,subject,create_time,update_time FROM clazz")
    List<Clazz> selectList();

    /**
     * 获取所有班级和学生数
     * @return
     */
    @MapKey("name")
    List<Map<String, Object>> countStudentData();
}
